﻿<Window x:Class="SyncSubsByComparison.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:vm="clr-namespace:SyncSubsByComparison"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:sysText="clr-namespace:System.Text;assembly=mscorlib"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="653" Width="1065" 
        xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
        Closing="Window_Closing" Icon="Untitled - 5.ico">
    <Window.DataContext>
        <vm:MainVM></vm:MainVM>
    </Window.DataContext>

    <Window.Resources>
        <ObjectDataProvider MethodName="GetValues"
        ObjectType="{x:Type sys:Enum}"
        x:Key="LineTypesEnum">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="vm:LineTypes" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider MethodName="GetEncodings"
        ObjectType="{x:Type sysText:EncodingInfo}"
        x:Key="EncodingsEnum">
        </ObjectDataProvider>

        <!-- Animated Expander Button's Template-->
        <ControlTemplate x:Key="AnimatedExpanderButtonTemp" TargetType="{x:Type ToggleButton}">
            <Border x:Name="ExpanderButtonBorder"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Padding="{TemplateBinding Padding}"
                    >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Rectangle Fill="Transparent"
                               Grid.ColumnSpan="2"/>
                    <Ellipse Name="Circle"
                         Grid.Column="0"
                         Stroke="DarkGray"
                         Width="20"
                         Height="20"
                         HorizontalAlignment="Center"
                         VerticalAlignment="Center"
                         />
                    <Path x:Name="Arrow"
                      Grid.Column="0"
                      Data="M 1,1.5 L 4.5,5 8,1.5"
                      Stroke="#FF666666"
                      StrokeThickness="2"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      RenderTransformOrigin="0.5,0.5"
                      >
                        <Path.RenderTransform>
                            <RotateTransform Angle="0"/>
                        </Path.RenderTransform>
                    </Path>
                    <ContentPresenter x:Name="HeaderContent"
                                      Grid.Column="1"
                                      Margin="4,0,0,0"
                                      ContentSource="Content"/>
                </Grid>
            </Border>
            <ControlTemplate.Triggers>
                <!-- Animate arrow when toggled-->
                <Trigger Property="IsChecked"
                         Value="True">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="Arrow"
                                                 Storyboard.TargetProperty="(Path.RenderTransform).(RotateTransform.Angle)"
                                                 To="180"
                                                 Duration="0:0:0.4"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                    <Trigger.ExitActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="Arrow"
                                                 Storyboard.TargetProperty="(Path.RenderTransform).(RotateTransform.Angle)"
                                                 To="0"
                                                 Duration="0:0:0.4"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.ExitActions>
                </Trigger>

                <!-- MouseOver, Pressed behaviours-->
                <Trigger Property="IsMouseOver"
                                 Value="true">
                    <Setter Property="Stroke"
                                    Value="#FF3C7FB1"
                                    TargetName="Circle"/>
                    <Setter Property="Stroke"
                                    Value="#222"
                                    TargetName="Arrow"/>
                </Trigger>
                <Trigger Property="IsPressed"
                                 Value="true">
                    <Setter Property="Stroke"
                                    Value="#FF526C7B"
                                    TargetName="Circle"/>
                    <Setter Property="StrokeThickness"
                                    Value="1.5"
                                    TargetName="Circle"/>
                    <Setter Property="Stroke"
                                    Value="#FF003366"
                                    TargetName="Arrow"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <!-- Stretch Out Content Expander's Template,
        Uses: AnimatedExpanderButtonTemp from above-->
        <ControlTemplate x:Key="StretchyExpanderTemp" TargetType="{x:Type Expander}">
            <DockPanel>
                <ToggleButton x:Name="ExpanderButton" 
                              DockPanel.Dock="Top"
                              Template="{StaticResource AnimatedExpanderButtonTemp}"
                              Content="{TemplateBinding Header}"
                              IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                              OverridesDefaultStyle="True"
                              Padding="1.5,0">
                </ToggleButton>
                <ContentPresenter x:Name="ExpanderContent"
                                  ContentSource="Content"
                                  DockPanel.Dock="Bottom"
                                  >
                    <ContentPresenter.LayoutTransform>
                        <ScaleTransform ScaleY="0"/>
                    </ContentPresenter.LayoutTransform>
                </ContentPresenter>
            </DockPanel>
            <ControlTemplate.Triggers>
                <Trigger Property="IsExpanded" Value="True">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="ExpanderContent"
                                                 Storyboard.TargetProperty="(ContentPresenter.LayoutTransform).(ScaleTransform.ScaleY)"                                                 
                                                 To="1"
                                                 Duration="0:0:0.4"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                    <Trigger.ExitActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="ExpanderContent"
                                                 Storyboard.TargetProperty="(ContentPresenter.LayoutTransform).(ScaleTransform.ScaleY)"
                                                 To="0"
                                                 Duration="0:0:0.4"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.ExitActions>
                </Trigger>

            </ControlTemplate.Triggers>
        </ControlTemplate>

    </Window.Resources>
    <Grid >
        <Popup Name="EditorInfoPopup" IsOpen="False" AllowsTransparency="True" Placement="Mouse"  MouseEnter="EditorInfoPopup_MouseEnter" >
            <Border Padding="5" CornerRadius="5" BorderThickness="1" BorderBrush="LightGray" SnapsToDevicePixels="True" Background="WhiteSmoke">
                <!--<TextBox Background="Transparent" Name="PopupText" BorderThickness="0" ></TextBox>-->
                <TextBlock Background="WhiteSmoke" Width="200" Name="PopupText" TextWrapping="NoWrap">
                </TextBlock>
            </Border>

        </Popup>
        <!--<TextBlock Background="Wheat" Width="150" Name="PopupText" TextWrapping="NoWrap">
            </TextBlock>-->
        <Button Content="Auto Sync" Height="23" Margin="0,77,12,0" Name="btnSync" VerticalAlignment="Top" Click="button1_Click" HorizontalAlignment="Right" Width="84" />
        <TextBox Height="23" Text="{Binding TimingSrtFile}" Name="txtTimingSrt" Margin="92,14,53.4,0" VerticalAlignment="Top" />
        <Button Name="btnTimingSubBrowse"  Height="23"  Margin="0,14,10.4,0" VerticalAlignment="Top" Click="btnTimingSubBrowse_Click" HorizontalAlignment="Right" Width="38">...</Button>
        <TextBox Height="23" Text="{Binding LanguageSrtFile}"  Name="txtLanguageSrt" Margin="92,48,296.4,0" VerticalAlignment="Top" />
        <ComboBox SelectedItem="{Binding SelectedEncodingName}" ItemsSource="{Binding AllEncodings}" Margin="0,48,127,0" HorizontalAlignment="Right" Width="121" Height="23" VerticalAlignment="Top"></ComboBox>
        <Label Content="timing srt:" Height="28" HorizontalAlignment="Left" Margin="10,12,0,0" Name="label1" VerticalAlignment="Top" />
        <Label Content="language srt:" Height="28" HorizontalAlignment="Left" Margin="10,46,0,0" Name="label2" VerticalAlignment="Top" />
        <Button Content="Add Translation" HorizontalAlignment="Right" Margin="0,48,12,0" Name="button3" Width="109" Height="23" VerticalAlignment="Top" Click="button3_Click" />
        <d3:ChartPlotter Margin="12,77,203,12" Name="plotter" IsEnabled="False" PreviewMouseUp="plotter_MouseUp" MouseMove="plotter_MouseMove" PreviewMouseDown="plotter_PreviewMouseDown" />
        <ScrollViewer Margin="0,105,0.4,-0.2" HorizontalAlignment="Right" Width="200" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <StackPanel   Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Left">
                <Expander Template="{StaticResource StretchyExpanderTemp}"
                  Width="200"
                  OverridesDefaultStyle="True"
                  HorizontalAlignment="Left"
                  VerticalAlignment="Top"
                      Header="Line Match Parameters" >

                    <Grid Height="190" Width="530" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="35*" />
                            <ColumnDefinition Width="168*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="57*" />
                            <RowDefinition Height="128*" />
                        </Grid.RowDefinitions>
                        <Slider Height="23" HorizontalAlignment="Left" Margin="6,27,0,0" Maximum="1" Minimum="0.4" Name="slider1" SmallChange="0.01" Value="{Binding MatchSimilarityThreshold}" VerticalAlignment="Top" Width="185" Grid.ColumnSpan="2" />
                        <Label Content="{Binding Path=Value, ElementName=slider1}" Height="28" HorizontalAlignment="Left" Margin="33,6,0,0" Name="label8" VerticalAlignment="Top" Width="67" Grid.Column="1" />
                        <Label Content="Similarity threshold:" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label9" VerticalAlignment="Top" Width="123" Grid.ColumnSpan="2" />
                        <Slider Height="23" HorizontalAlignment="Left" IsSnapToTickEnabled="True" Margin="6,20,0,0" Maximum="50" Minimum="1" Name="slider2" SmallChange="1" Value="{Binding MatchMinimumLettersForMatch}" VerticalAlignment="Top" Width="185" Grid.Row="1" Grid.ColumnSpan="2" />
                        <Label Content="{Binding Path=Value, ElementName=slider2}" Height="28" HorizontalAlignment="Left" Margin="36,56,0,0" Name="label10" VerticalAlignment="Top" Width="57" Grid.RowSpan="2" Grid.Column="1" />
                        <Label Content="Minimal match (ltrs):" HorizontalAlignment="Left" Margin="6,56,0,0" Name="label11" Width="131" Height="28" VerticalAlignment="Top" Grid.RowSpan="2" Grid.ColumnSpan="2" />
                        <Slider Height="23" HorizontalAlignment="Left" IsSnapToTickEnabled="True" Margin="6,70,0,0" Maximum="50" Minimum="1" Name="slider3" SmallChange="0.1" TickFrequency="0.1" Value="{Binding MatchLinesToSearchForward}" VerticalAlignment="Top" Width="185" Grid.Row="1" Grid.ColumnSpan="2" />
                        <Label Content="{Binding Path=Value, ElementName=slider3}" Height="28" HorizontalAlignment="Left" Margin="29,49,0,0" Name="label12" VerticalAlignment="Top" Width="71" Grid.Row="1" Grid.Column="1" />
                        <Label Content="Lines to search fwd:" Height="28" HorizontalAlignment="Left" Margin="6,49,0,0" Name="label13" VerticalAlignment="Top" Width="123" Grid.Row="1" Grid.ColumnSpan="2" />
                        <Label Content="{Binding CountMatchPoints}" Height="28" Margin="16,99,0,0" Name="lblCountMatchPoints" VerticalAlignment="Top" FontWeight="Bold" HorizontalAlignment="Left" Width="84" Grid.Row="1" Grid.Column="1" />
                        <Label Content="Matched Lines:" Margin="6,99,0,0" Name="label15" FontWeight="Bold" Height="28" VerticalAlignment="Top" HorizontalAlignment="Left" Width="101" Grid.Row="1" Grid.ColumnSpan="2" />
                    </Grid>
                </Expander>
                <Expander
                    Template="{StaticResource StretchyExpanderTemp}" OverridesDefaultStyle="True"
                	HorizontalAlignment="Left"
                	VerticalAlignment="Top"
                	Header="Baseline Parameters"
                	Margin="0,10,0,0" >
                    <Grid  Height="200" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="32*" />
                            <ColumnDefinition Width="1009*" />
                        </Grid.ColumnDefinitions>
                        <Slider Value="{Binding BaselineAlgAlpha}" Height="23" Minimum="0.01" Maximum="0.6" Margin="9,51,0,0" x:Name="sldAlpha" VerticalAlignment="Top" SmallChange="0.01" HorizontalAlignment="Left" Width="185" Grid.Column="1" />
                        <Label Content="{Binding Value, ElementName=sldAlpha}" Height="28" Margin="116,30,0,0" x:Name="alpha" VerticalAlignment="Top" Grid.Column="1" HorizontalAlignment="Left" Width="78" />
                        <Label Content="Algorithm alpha:" Height="28" Margin="9,30,0,0" x:Name="label3" VerticalAlignment="Top" Grid.Column="1" HorizontalAlignment="Left" Width="101" />
                        <Slider Height="23" Margin="9,101,0,0" Maximum="50" Minimum="1" x:Name="sldStartSection" SmallChange="1" Value="{Binding StartSectionLength}" VerticalAlignment="Top" HorizontalAlignment="Left" Width="185" IsSnapToTickEnabled="True" Grid.Column="1" />
                        <Label Content="{Binding Value, ElementName=sldStartSection}" Height="28" Margin="116,80,0,0" x:Name="label4" VerticalAlignment="Top" HorizontalAlignment="Left" Width="72" Grid.Column="1" />
                        <Label Content="Start sect. length:" Height="28" HorizontalAlignment="Left" Margin="9,80,0,0" x:Name="label5" VerticalAlignment="Top" Width="101" Grid.Column="1" />
                        <CheckBox Content="Remove abnormal points" IsChecked="{Binding RemoveAbnormalPoints}" Height="16" HorizontalAlignment="Left" Margin="9,174,0,0" x:Name="checkBox1" VerticalAlignment="Top" Width="154" Grid.Column="1" />
                        <!--<CheckBox Content="Sync to orig. match" Height="16" HorizontalAlignment="Left" IsChecked="{Binding SyncAccordingToMatch}" Margin="9,178,0,0" Name="checkBox2" VerticalAlignment="Top" Width="154" Grid.Column="1" />-->
                        <Slider Height="23" HorizontalAlignment="Left"  Margin="9,151,0,0" Maximum="5" Minimum="0.5" x:Name="sldAbnormalZoneAmp" SmallChange="0.1" Value="{Binding NormalZoneAmplitude}" VerticalAlignment="Top" Width="185" TickFrequency="0.1" IsSnapToTickEnabled="True" Grid.Column="1" />
                        <Label Content="{Binding Value, ElementName=sldAbnormalZoneAmp}" Height="28" HorizontalAlignment="Left" Margin="131,130,0,0" x:Name="label6" VerticalAlignment="Top" Width="57" Grid.Column="1" />
                        <Label Content="Normal Zone Amp:" Height="28" HorizontalAlignment="Left" Margin="8,130,0,0" x:Name="label7" VerticalAlignment="Top" Width="123" Grid.Column="1" />
                        <CheckBox Content="Show baseline graph" IsChecked="{Binding ShowBaselineGraph}" Height="16" HorizontalAlignment="Left" Margin="9,10,0,0" VerticalAlignment="Top" Width="154" Grid.Column="1"  />
                    </Grid>
                </Expander>


                <Expander  VerticalAlignment="Top" Header="Step Line Parameters" Margin="0,10,0,0" IsExpanded="False" Width="200" HorizontalAlignment="Left" Template="{StaticResource StretchyExpanderTemp}" OverridesDefaultStyle="True">
                    <Grid HorizontalAlignment="Left" Height="150">
                        <Label Margin="6,21,-8,52" HorizontalAlignment="Left" Width="200">Number of lines:</Label>
                        <Label Content="{Binding Path=Value, ElementName=sld}" Height="28" HorizontalAlignment="Left" Margin="101,21,0,0" VerticalAlignment="Top" Width="57" />
                        <Slider Value="{Binding NumberOfStepLines}" Height="23" Minimum="1" Maximum="15" Margin="21,42,-8,0" Name="sld" VerticalAlignment="Top" SmallChange="1" HorizontalAlignment="Left" Width="185" />
                        <Label Margin="6,57,-8,19" HorizontalAlignment="Left" Width="200">Num Points to jump step:</Label>
                        <Label Content="{Binding Path=Value, ElementName=sld1}" Height="28" HorizontalAlignment="Left" Margin="151,57,-10,0" VerticalAlignment="Top" Width="57" />
                        <Slider Value="{Binding NumberOfPointsToJumpStep}" Height="23" Minimum="1" Maximum="15" Margin="21,79,-8,0" Name="sld1" VerticalAlignment="Top" SmallChange="1" HorizontalAlignment="Left" Width="185" />
                        <CheckBox Content="Require consecutive points" IsChecked="{Binding StepsAlgRequiresConsecutive}" Height="16" HorizontalAlignment="Left" Margin="11,107,0,0" VerticalAlignment="Top" Width="154" />
                        <CheckBox Content="Remove redundant lines" IsChecked="{Binding StepsAlgRemoveRedundentLines}" Height="16" HorizontalAlignment="Left" Margin="11,128,0,0" VerticalAlignment="Top" Width="154" />
                        <CheckBox Content="Show step graph" IsChecked="{Binding ShowStepGraph}" Height="16" HorizontalAlignment="Left" Margin="11,5,0,0" VerticalAlignment="Top" Width="154" />
                    </Grid>
                </Expander>
                <Expander OverridesDefaultStyle="True" Template="{StaticResource StretchyExpanderTemp}" Header="Microsoft Translation Config" Margin="0,10,0,0" IsExpanded="False" Width="200" HorizontalAlignment="Left">
                    <Grid HorizontalAlignment="Left" Width="197" Height="58">
                        <Label Margin="-1,2,0,-2" HorizontalAlignment="Left" Width="52" >ClientID:</Label>
                        <TextBox Margin="56,2,0.4,0" Text="{Binding  UpdateSourceTrigger=PropertyChanged, Path=MSSearchClientID}" Height="22" VerticalAlignment="Top"></TextBox>
                        <Label Margin="0,26,0,0" HorizontalAlignment="Left" Width="52">Secret:</Label>
                        <TextBox Margin="56,29,0,0"  Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=MSSearchSecret}"  Height="22" VerticalAlignment="Top"></TextBox>
                    </Grid>
                </Expander>
                <Expander OverridesDefaultStyle="True" Template="{StaticResource StretchyExpanderTemp}" VerticalAlignment="Top"  Header="Fix &amp; Save Subtitle" Margin="0,10,0,0" IsExpanded="True" Width="200" HorizontalAlignment="Left">
                    <Grid HorizontalAlignment="Left">
                        <Label Margin="-1,0,0,0" HorizontalAlignment="Left" Width="52">use line:</Label>
                        <ComboBox SelectedItem="{Binding SelectedLineType}" ItemsSource="{Binding Source={StaticResource LineTypesEnum}}" Margin="56,2,0.4,0" Height="22" VerticalAlignment="Top"></ComboBox>
                        <Button Content="Save Srt File" Height="23"  Name="btnSave" VerticalAlignment="Top" HorizontalAlignment="Center" Width="165" Click="btnSave_Click" Margin="16,31,17.4,-28.4" />
                    </Grid>
                </Expander>


            </StackPanel>
        </ScrollViewer>
        <Button Content="Update Graph" Height="23" Margin="0,77,102,0" Name="button1" VerticalAlignment="Top" HorizontalAlignment="Right" Width="95" Click="button1_Click_1" />
        <Button Height="23"  Margin="0,48,253.4,0" Name="btnLangSubBrowse" VerticalAlignment="Top" Content="..." Click="btnLangSubBrowse_Click" HorizontalAlignment="Right" Width="38"/>
    </Grid>
    <Window.Background>
        <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
            <GradientStop Color="White" Offset="1" />
            <GradientStop Color="#FFC4E1FF" Offset="0" />
            <GradientStop Color="#FFD2EEFF" Offset="0.284" />
        </LinearGradientBrush>
    </Window.Background>
</Window>
